<?php

/**
 * Mallkit eCommerce API
 *
 * @version 	$Id: mallkit_ec.php 16 2009-01-30 06:52:12Z codemaster@mallkit.org $
 * @package 	XMLRPC
 * @subpackage 	RPC
 *
 * @copyright	Copyright (C) 2004-2009 saurabh - All rights reserved.
 * @license 	GNU/GPL, see LICENSE.php
 *
 * This file is part of Mallkit eCommerce.
 *
 * Mallkit eCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Mallkit eCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License.
 * If not, see <http://www.gnu.org/licenses/>.
 *
 * @website	http://mallkit.org
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

/**
* Import joomla's JPlugin class
*/
jimport('joomla.plugin.plugin');

/**
 * The Class plgXMLRPCMallkit_EC extends JPlugin
 *
 * @package	XMLRPC
 */
class plgXMLRPCMallkit_EC extends JPlugin
{
	
	/**
	 * Get Web Services
	 *
	 * The function onGetWebServices() 
	 * 
	 * @access	public
	 * @return	array $services	Array of web service descriptors
	 * @version 1.0
	 */
	function onGetWebServices(){
	
	global $mainframe, $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	$services = array(
		
		// Get Featured Products
		'mallkit_ec.getProductsFeatured' => array(
		'function' => 'plgXMLRPCMallkit_ECServices::getProductsFeatured',
		'docstring' => 'Get Featured Products',
		'signature' => array(array($xmlrpcArray, $xmlrpcInt, $xmlrpcString))
		),
		
		// Get Popular Products
		'mallkit_ec.getProductsPopular' => array(
		'function' => 'plgXMLRPCMallkit_ECServices::getProductsPopular',
		'docstring' => 'Get Popular Products',
		'signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcInt))
		),

		// Get Recently Added Products
		'mallkit_ec.getProductsRecentlyAdded' => array(
		'function' => 'plgXMLRPCMallkit_ECServices::getProductsRecentlyAdded',
		'docstring' => 'Get Recently Added Products',
		'signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcInt, $xmlrpcString))
		),

		// Get List of Payment Methods
		'mallkit_ec.getPaymentMethods' => array(
		'function' => 'plgXMLRPCMallkit_ECServices::getPaymentMethods',
		'docstring' => 'Get List of Payment Methods',
		'signature' => array(array($xmlrpcArray))
		),

		// Get Product Reviews
		'mallkit_ec.getProductReviews' => array(
		'function' => 'plgXMLRPCMallkit_ECServices::getProductReviews',
		'docstring' => 'Get Product Reviews',
		'signature' => array(array($xmlrpcArray, $xmlrpcInt, $xmlrpcInt))
		),

		// Get Product By Keyword
		'mallkit_ec.getProductByKeyword' => array(
		'function' => 'plgXMLRPCMallkit_ECServices::getProductByKeyword',
		'docstring' => 'Get Product by Keyword',
		'signature' => array(array($xmlrpcArray, $xmlrpcString))
		),
		
		// Get Order Details
		'mallkit_ec.getOrderDetails' => array(
		'function' => 'plgXMLRPCMallkit_ECServices::getOrderDetails',
		'docstring' => 'Get Order Details',
		'signature' => array(array($xmlrpcArray, $xmlrpcInt, $xmlrpcInt))
		),

		// Get Product Categories
		'mallkit_ec.getCategories' => array(
		'function' => 'plgXMLRPCMallkit_ECServices::getCategories',
		'docstring' => 'Get Product Categories',
		'signature' => array(array($xmlrpcArray, $xmlrpcString, $xmlrpcInt, $xmlrpcInt))
		)
	);
	
	return $services;
	
	}
	
}

/**
 * The Class plgXMLRPCMallkit_ECServices
 *
 * @package XMLRPC
 */
class plgXMLRPCMallkit_ECServices
{

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Product Functions
	
	/**
	 * Get All Products
	 *
	 * The function getProducts() 
	 * 
	 * @access 	public
	 * @return	array xmlrpcresp
	 * @version 1.0
	 */ 
	function getProducts()
	{
	
		global $xmlrpcArray;
	
	}
	
	/**
	 * Get Featured Products
	 *
	 * The function getProductsFeatured()
	 *
	 * @todo Code Commenting
	 * 
	 * @param 	integer $numtodisplay 	Number of products to get
	 * @param 	string 	$categories 	Get products in these categories only (optional)
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getProductsFeatured($numtodisplay, $categories)
	{
	
		global $xmlrpcInt, $xmlrpcString, $xmlrpcArray;
		
		if($categories != '')
		{
			$cat_check = strstr($categories,',');
			
			if($cat_check)
			{
				$categories = str_replace(' ','',$categories);
				$categories = str_replace(',', ' OR p.category_id = ', '(p.category_id = '. $categories .') AND ');		
			}
			else
			{
				$categories = ' p.category_id = '. $categories .' AND ';
			}
		}
	
		$query = 'SELECT p.name AS name, MIN( v.price ) AS price , i.path_md AS image FROM #__mk_products AS p, #__mk_products_image AS i, #__mk_products_variation AS v WHERE p.b_published = 1 AND p.product_id = i.product_id AND '. $categories .' i.b_featured = 1 AND p.b_featured = 1 AND v.product_id = p.product_id GROUP BY v.product_id ORDER BY p.product_id limit 0, '.$numtodisplay;

		$db =& JFactory::getDBO();
		$db->setQuery( $query );
		$products = $db->loadObjectList();
		$structarray = array();
			
		foreach($products AS $product) 
		{
			$record = new xmlrpcval(array(
				'name' => new xmlrpcval($product->name, $xmlrpcString),
				'price' => new xmlrpcval($product->price, $xmlrpcString),
				'image' => new xmlrpcval($product->image, $xmlrpcString)
				), 'struct');
			array_push($structarray, $record);
		}

		// Append SQL queries when debug mode is enabled
		plgXMLRPCMallkit_ECHelper::appendQuery($structarray, $query);
		
		return new xmlrpcresp(new xmlrpcval($structarray, $xmlrpcArray));
	
	}
	
	/**
	 * Get Popular Products
	 *
	 * The function getProductsPopular()
	 *
	 * @todo Code Commenting 
	 *
	 * @param 	integer $numtodisplay 	Number of products to get
	 * @param 	string 	$categories 	Get products in these categories only (optional)
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getProductsPopular($numtodisplay, $categories)
	{
	
		global $xmlrpcInt, $xmlrpcString, $xmlrpcArray;
		
		if($categories != '')
		{
			$cat_check = strstr($categories,',');
			
			if($cat_check)
			{
				$categories = str_replace(' ','',$categories);
				$categories = str_replace(',', ' OR p.category_id = ', '(p.category_id = '. $categories .') AND ');		
			}
			else
			{
				$categories = ' p.category_id = '. $categories .' AND ';
			}
		}
			
		$query = 'SELECT p.name AS name, MIN( v.price ) AS price , i.path_md AS image FROM #__mk_products AS p, #__mk_products_image AS i, #__mk_products_variation AS v WHERE p.b_published = 1 AND p.product_id = i.product_id AND '. $categories .' i.b_featured = 1 AND p.b_featured = 1 AND v.product_id = p.product_id GROUP BY v.product_id ORDER BY p.product_id limit 0, '.$numtodisplay;
		$db =& JFactory::getDBO();
		$db->setQuery( $query );
		$products = $db->loadObjectList();
		$structarray = array();
		
		foreach($products AS $product)
		{
			$record = new xmlrpcval(array(
			'name' => new xmlrpcval($product->name, $xmlrpcString),
			'price' => new xmlrpcval($product->price, $xmlrpcString),
			'image' => new xmlrpcval($product->image, $xmlrpcString)
			), 'struct');
			array_push($structarray, $record);
		}
			
		// Append SQL queries when debug mode is enabled
		plgXMLRPCMallkit_ECHelper::appendQuery($structarray, $query);

		return new xmlrpcresp(new xmlrpcval($structarray, $xmlrpcArray));
	
	}
	
	/**
	 * Get Recently Added Products
	 *
	 * The function getProductsRecentlyAdded()
	 *
	 * @todo Code Commenting
	 * 
	 * @param 	integer $numtodisplay 	Number of products to get
	 * @param 	array 	$categories 	Get products in these categories only (optional)
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getProductsRecentlyAdded($numtodisplay, $categories)
	{
	
		global $xmlrpcInt, $xmlrpcString, $xmlrpcArray;
		
		if($categories != '')
		{
			$cat_check = strstr($categories,',');
			
			if($cat_check)
			{
				$categories = str_replace(' ','',$categories);
				$categories = str_replace(',', ' OR p.category_id = ', '(p.category_id = '. $categories .') AND ');		
			}
			else
			{
				$categories = ' p.category_id = '. $categories .' AND ';
			}
		}
		
		$query = 'SELECT p.name AS name, MIN( v.price ) AS price , i.path_md AS image FROM #__mk_products AS p, #__mk_products_image AS i, #__mk_products_variation AS v WHERE p.b_published = 1 AND p.product_id = i.product_id AND i.b_featured = 1 AND '. $categories .' v.product_id = p.product_id GROUP BY v.product_id ORDER BY p.c_date DESC limit 0, '.$numtodisplay;
		$db =& JFactory::getDBO();
		$db->setQuery( $query );
		$products = $db->loadObjectList();
		$structarray = array();
		
		foreach($products AS $product)
		{
			$record = new xmlrpcval(array(
			'name' => new xmlrpcval($product->name, $xmlrpcString),
			'price' => new xmlrpcval($product->price, $xmlrpcString),
			'image' => new xmlrpcval($product->image, $xmlrpcString)
			), 'struct');
			array_push($structarray, $record);
		}
		
		// Append SQL queries when debug mode is enabled
		plgXMLRPCMallkit_ECHelper::appendQuery($structarray, $query);

		return new xmlrpcresp(new xmlrpcval($structarray, $xmlrpcArray));
	
	}
	
	/**
	 * Get Recently Viewed Products
	 *
	 * The function getProductsRecentlyViewed() 
	 * 
	 * @param 	integer $numtodisplay 	Number of products to get
	 * @param 	array 	$products 		Get these products
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getProductsRecentlyViewed()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Get Products by Category
	 *
	 * The function getProductsByCategory() 
	 * 
	 * @param 	integer $category_id 	Get all products in this category
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getProductsByCategory()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Get Products By Search Criteria
	 *
	 * The function getProductsByCategory() 
	 * 
	 * @param 	string 	$search_term 	Get all products matching the search criteria
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getProductsBySearch()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}

	/**
	 * Get Products By Keyword
	 *
	 * The function getProductByKeyword() 
	 * 
	 * @param 	string 	$keyword 	Get all products matching the keyword
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getProductByKeyword($keyword, $limit)
	{
	
		global $mainframe, $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
		
		$query = 'SELECT i.path_md AS path, p.name AS name from jos_mk_products_keyword as k, jos_mk_products as p, jos_mk_products_image as i, jos_mk_products_variation as v where k.keyword = '.$keyword .' and k.product_id = p.product_id and i.product_id = p.product_id and i.b_featured = 1 and p.b_published = 1 and p.b_archived = 0 and v.b_published = 1 and v.b_archived = 0 and v.product_id = p.product_id limit 0, '. $limit;
		
		$db =& JFactory::getDBO();
		$db->setQuery( $query );
		$products = $db->loadObjectList();
		$structarray = array();
		
		foreach($products AS $product) 
		{
			$record = new xmlrpcval(array(
				'path' => new xmlrpcval($product->path, $xmlrpcString),
				'name' => new xmlrpcval($product->name, $xmlrpcString)
				), 'struct');
			array_push($structarray, $record);
		}
		
		// Append SQL queries when debug mode is enabled
		plgXMLRPCMallkit_ECHelper::appendQuery($structarray, $query);

		return new xmlrpcresp(new xmlrpcval($structarray, $xmlrpcArray));
	
	}
		
	/**
	 * Get Product Details
	 *
	 * The function getProductDetails() 
	 * 
	 * @param 	integer $product_id 	Get the details of this product
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getProductDetails()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Get Product Reviews
	 *
	 * The function getProductReviews() 
	 * 
	 * @param 	integer $product_id 	Get the reviews of this product
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getProductReviews($product_id, $limit)
	{ 
		global $mainframe, $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
		
		$query = 'SELECT r.name as name, r.comment as comment FROM #__mk_products as p, #__mk_products_review as r where p.b_published = 1 and p.b_archived = 0 and r.b_published = 1 and r.b_archived = 0 and p.product_id = r.product_id and p.product_id = ' . $product_id . ' order by r.c_date limit 0, ' . $limit;
		$db =& JFactory::getDBO();
		$db->setQuery( $query );
		$reviews = $db->loadObjectList();
		$structarray = array();
		
		foreach($reviews AS $review) 
		{
			$record = new xmlrpcval(array(
				'name' => new xmlrpcval($review->name, $xmlrpcString),
				'comment' => new xmlrpcval($review->comment, $xmlrpcString)
				), 'struct');
			array_push($structarray, $record);
		}
		
		// Append SQL queries when debug mode is enabled
		plgXMLRPCMallkit_ECHelper::appendQuery($structarray, $query);

		return new xmlrpcresp(new xmlrpcval($structarray, $xmlrpcArray));
	
	}
	
	/**
	 * Get All Categories
	 *
	 * The function getCategories()
	 *
	 * @todo Code Commenting 
	 * 
	 * @access 	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getCategories($product_id, $limit)
	{
	
		global $mainframe, $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
		$query = 'SELECT * FROM #__mk_lkp_categories ' . 'WHERE parent_id =' . $parent_id . ' limit 0, '.$limit;
		$db =& JFactory::getDBO();
		$db->setQuery( $query );
		$products = $db->loadObjectList();
		$structarray = array();
		
		foreach($products AS $product) 
		{
			$record = new xmlrpcval(array(
				'category' => new xmlrpcval($product->category, $xmlrpcString),
				'category_id' => new xmlrpcval($product->category_id, $xmlrpcString)
				), 'struct');
			array_push($structarray, $record);
		}
		
		// Append SQL queries when debug mode is enabled
		plgXMLRPCMallkit_ECHelper::appendQuery($structarray, $query);

		return new xmlrpcresp(new xmlrpcval($structarray, $xmlrpcArray));
	
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Order Functions

	/**
	 * Get Recent Orders placed by User
	 *
	 * The function getOrdersByUser() 
	 * 
	 * @param 	integer $user_id 	Get the orders placed by this user
	 * @access	protected
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getOrdersByUser()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Get Orders Details
	 *
	 * The function getOrderDetails() 
	 * 
	 * @param 	integer $order_id 	Get the details of this order
	 * @access	protected
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getOrderDetails($order_id, $user_id)
	{
	
		global $mainframe, $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
		$query = 'SELECT sh.ship_status AS ship_status, sp.pay_status AS pay_status, m.title AS title, u.first_name AS first_name, u.last_name AS last_name, o.order_number AS order_number, o.c_date AS c_date, o.total AS total, o.subtotal AS subtotal, o.ship_rate AS ship_rate, o.tax_rate AS tax_rate from jos_mk_lkp_status_payment AS sp, jos_mk_lkp_status_shipping AS sh, jos_mk_methods_payment AS m, jos_mk_orders AS o, jos_mk_users AS u where o.order_id = '. $order_id .' and o.user_id = u.user_id and u.user_id = '. $user_id .' and o.pay_method_id = m.pay_method_id and o.pay_status_id = sp.pay_status_id and o.ship_status_id = sh.ship_status_id';

		$db =& JFactory::getDBO();
		$db->setQuery( $query );
		$orders = $db->loadObjectList();
		$structarray = array();
			
		foreach($orders AS $order) 
		{
			$order = new xmlrpcval(array(
				'ship_status' => new xmlrpcval($method->ship_status, $xmlrpcString),
				'pay_status' => new xmlrpcval($method->pay_status, $xmlrpcString),
				'title' => new xmlrpcval($method->title, $xmlrpcString),
				'first_name' => new xmlrpcval($method->first_name, $xmlrpcString),
				'last_name' => new xmlrpcval($method->last_name, $xmlrpcString),
				'order_number' => new xmlrpcval($method->order_number, $xmlrpcString),
				'c_date' => new xmlrpcval($method->c_date, $xmlrpcString),
				'total' => new xmlrpcval($method->ship_status, $xmlrpcString),
				'subtotal' => new xmlrpcval($method->total, $xmlrpcString),
				'ship_rate' => new xmlrpcval($method->ship_rate, $xmlrpcString),
				'tax_rate' => new xmlrpcval($method->tax_rate, $xmlrpcString)
				), 'struct');
			array_push($structarray, $record);
		}

		// Append SQL queries when debug mode is enabled
		plgXMLRPCMallkit_ECHelper::appendQuery($structarray, $query);
		
		return new xmlrpcresp(new xmlrpcval($structarray, $xmlrpcArray));
	}
	

	/**
	 * Get Payment Methods
	 *
	 * The function getPaymentMethods() 
	 * 
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getPaymentMethods()
	{
	
		global $mainframe, $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;

		$query = 'SELECT title from #__mk_methods_payment';

		$db =& JFactory::getDBO();
		$db->setQuery( $query );
		$methods = $db->loadObjectList();
		$structarray = array();
			
		foreach($methods AS $method) 
		{
			$record = new xmlrpcval(array(
				'title' => new xmlrpcval($method->title, $xmlrpcString)
				), 'struct');
			array_push($structarray, $record);
		}

		// Append SQL queries when debug mode is enabled
		plgXMLRPCMallkit_ECHelper::appendQuery($structarray, $query);
		
		return new xmlrpcresp(new xmlrpcval($structarray, $xmlrpcArray));
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Shipping Functions
	
	/**
	 * Get Shipping Rates
	 *
	 * The function getShippingRates() 
	 * 
	 * @param 	integer $country_id 	Get the shipping rate of this country
	 * @param 	integer $province_id 	Get the shipping rate of this province (optional)
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getShippingRates()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Tax Functions
	
	/**
	 * Get Tax Rates
	 *
	 * The function getTaxRates() 
	 * 
	 * @param 	integer $country_id 	Get the shipping rate of this country
	 * @param 	integer $province_id 	Get the shipping rate of this province (optional)
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getTaxRates()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// User Functions
	
	/**
	 * Get User Account Information
	 *
	 * The function getAccountInfo()
	 * 
	 * @param 	integer $user_id 	Get Account information for this user
	 * @access	protected
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getAccountInfo()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Add Product to User's Cart
	 *
	 * The function addToCart() 
	 * 
	 * @param 	integer $user_id 	Add a product to this user's cart
	 * @access	protected
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function addToCart()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Get User's Cart Details
	 *
	 * The function getCart() 
	 * 
	 * @param 	integer $user_id 	Get cart details from this user's cart
	 * @access	protected
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getCart()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Insert Shipping Address
	 *
	 * The function addShippingAddress() 
	 * 
	 * @param 	integer $user_id 	Add shipping address for this user
	 * @access	protected
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function addShippingAddress()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Add Billing Address
	 *
	 * The function addBillingAddress() 
	 * 
	 * @param 	integer	$user_id 	Add billing address for this user
	 * @access	protected
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function addBillingAddress()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Get Currency Conversion
	 *
	 * The function getCurrencyConvert() 
	 * 
	 * @param 	float 	$amount 			Amount to convert
	 * @param	string	$start_currency 	Starting currency format
	 * @param	string	$end_currency 		Ending currency format
	 * @access	public
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getCurrencyConvert()
	{
	
		global $mainframe,
		$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	/**
	 * Export Data to CSV
	 *
	 * The function exportCSV() 
	 * 
	 * @param 	string 	$filePoiner The file resource to write to
	 * @param 	array 	$dataArray	The data to write out
	 * @param 	array 	$delimiter 	Array data delimiter
	 * @param 	array 	$enclosure 	The field separator
	 * @return	success/failure
	 * @access	protected
	 * @version 1.0
	 */
	function exportCSV($filePointer,$dataArray,$delimiter=",",$enclosure="\""){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	// Build the string
	$string = "";
		 
	// for each array element, which represents a line in the csv file...
	foreach($dataArray as $line){
		
		// No leading delimiter
		$writeDelimiter = FALSE;
			   
		foreach($line as $dataElement){
		
			// Replaces a double quote with two double quotes
			$dataElement=str_replace("\"", "\"\"", $dataElement);
				   
			// Adds a delimiter before each field (except the first)
			if($writeDelimiter) $string .= $delimiter;
				   
			// Encloses each field with $enclosure and adds it to the string
			$string .= $enclosure . $dataElement . $enclosure;
				   
			// Delimiters are used every time except the first.
			$writeDelimiter = TRUE;
		}
		
		// Append new line
		$string .= "\n";
		
	} // end foreach($dataArray as $line)
		
	// Write the string to the file
	fwrite($filePointer,$string);
	
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Product Functions
	
	/**
	 * Add New Product
	 *
	 * The function addNewProduct() 
	 * 
	 * @access 	protected
	 * @return	success/failure
	 * @version 1.0
	 */
	function addNewProduct(){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Export Products to CSV
	 *
	 * The function exportProductsCSV() 
	 * 
	 * @param 	array 	$dataArray	The data to write out
	 * @access	protected
	 * @return	success/failure
	 * @version 1.0
	 */
	function exportProductsCSV($dataArray){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
			
	// call function to export data
	exportCSV('filePointer','dataArray');
	
	}
	
	/**
	 * Get Inventory Warnings
	 *
	 * The function getInventoryWarnings() 
	 *
	 * @access	protected
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getInventoryWarnings(){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Order Functions

	/**
	 * Get New Orders
	 *
	 * The function getNewOrders() 
	 * 
	 * @access	protected
	 * @return	xmlrpcresp
	 * @version 1.0
	 */
	function getNewOrders(){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Export Orders to CSV
	 *
	 * The function exportOrdersCSV() 
	 * 
	 * @param 	array 	$dataArray	The data to write out
	 * @access	protected
	 * @return	success/failure
	 * @version 1.0
	 */
	function exportOrdersCSV($dataArray){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
			
	// call function to export data
	exportCSV('filePointer','dataArray');
	
	}
	
	/**
	 * Update Shipping Status
	 *
	 * The function updateShippingStatus() 
	 * 
	 * @param 	interger $order_id	Update shipping status on this order
	 * @access	protected
	 * @return	success/failure
	 * @version 1.0
	 */
	function updateShippingMethods(){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Update Payment Status
	 *
	 * The function updatePaymentStatus() 
	 * 
	 * @param 	interger $order_id	Update shipping status on this order
	 * @access	protected
	 * @return	success/failure
	 * @version 1.0
	 */
	function updatePaymentStatus(){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Shipping Functions
	
	/**
	 * Add Shipping Rates
	 *
	 * The function addShippingRates() 
	 * 
	 * @access	protected
	 * @return	success/failure
	 * @version 1.0
	 */
	function addShippingRates(){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Tax Functions
	
	/**
	 * Add Tax Rates
	 *
	 * The function addTaxRates() 
	 * 
	 * @access	protected
	 * @return	success/failure
	 * @version 1.0
	 */
	function addTaxRates(){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Store Functions
	
	/**
	 * Add Store Information
	 *
	 * The function addStore()
	 * 
	 * @access	protected
	 * @return	success/failure
	 * @version 1.0
	 */
	function addStore(){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	/**
	 * Modify Store Information
	 *
	 * The function modifyStore() 
	 * 
	 * @param 	integer $store_id Modify this store
	 * @access	protected
	 * @return	success/failure
	 * @version 1.0
	 */
	function modifyStore(){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
	
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// User Functions
	
	/**
	 * Export Users to CSV
	 *
	 * The function exportUsersCSV() 
	 * 
	 * @param 	array 	$dataArray	The data to write out
	 * @access	protected
	 * @return	success/failure
	 * @version 1.0
	 */
	function exportUsersCSV($dataArray){
	
	global $mainframe,
	$xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
			
	// call function to export data
	exportCSV('filePointer','dataArray');
	
	}
}

/**
 * The Class plgXMLRPCMallkit_ECHelper
 *
 * @package	XMLRPC
 */
class plgXMLRPCMallkit_ECHelper
{
	/**
	 * Append SQL Query into returned XML
	 *
	 * The function appendQuery() 
	 * 
	 * @param 	array 	$structarray 		Array that contains XML
	 * @param	string	$query				Query to append
	 * @access	public
	 * @return	
	 * @version 1.0
	 */
	function appendQuery(&$structarray, $query)
	{
		$plugin =& JPluginHelper::getPlugin('xmlrpc', 'mallkit_ec');
		$params = new JParameter($plugin->params);
		if ($params->get('debugmode')) {
			array_push($structarray, new xmlrpcval($query, $xmlrpcString));
		}
	}
}










?>